package edu.uniquindio.prmaven.dataprovider;

import java.lang.reflect.Method;
import java.util.HashMap;
import java.util.Map;

public class DataProviderUtils {
	protected static Map<String, String> resolveDataProviderArguments(
			Method testMethod) throws Exception {
		if (testMethod == null)
			throw new IllegalArgumentException (
					"test Method context cannot be null." );
		
		DataProviderArguments args = testMethod
				.getAnnotation(DataProviderArguments.class);
		if (args == null)
			throw new IllegalArgumentException(
					"test Method has not DataProviderArguments annotantion.");
		if (args.value() == null || args.value().length ==0)
			throw new IllegalArgumentException(
					"test Method has a malformed DataProviderArguments annotantion.");
		Map<String, String> arguments = new HashMap<String, String>();
		for (int i=0; i<args.value().length; i++) {
			String [] parts = args.value() [i].split("=");
			arguments.put(parts[0], parts[1]);
		}
	return arguments;
	}
	

}
